#include "si7006.h"
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>

int main(int argc, const char* argv[])
{
    int fd, serial, firware, tmpcode, humcode;
    float tmp, hum;
    if ((fd = open("/dev/si7006", O_RDWR)) < 0) {
        perror("open error");
        exit(EXIT_FAILURE);
    }

    ioctl(fd, GET_SERIAL, &serial);
    ioctl(fd, GET_FIRWARE, &firware);

    printf("serial = %#x,firware = %#x\n", serial, firware);
    while (1) {
        ioctl(fd, GET_TMP, &tmpcode);
        ioctl(fd, GET_HUM, &humcode);

        hum = 125.0 * humcode / 65536 - 6;
        tmp = 175.72 * tmpcode / 65536 - 46.85;

        printf("tmp=%.2f,hum=%.2f\n",tmp,hum);
        sleep(1);
    }
    close(fd);
    return 0;
}